package cm.cool.web.service.param;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import cm.cool.web.bean.Param;
import cm.cool.web.data.ParamMapper;
import cm.cool.web.util.respon.R;
import cm.cool.web.util.respon.ResultEncoding;

@Service
public class ParamService {
	
	@Autowired
	ParamMapper paramMapper;
	
	/**
	 * 查找所有的Ec参数
	 * @return
	 */
	public R findAll(Param params){
		R r = new R();
		try {
			r.setData(paramMapper.selectAll(params));
			return r;
		} catch (Exception e) {
			e.printStackTrace();
			r.setCode(ResultEncoding.R_ERR);
			r.setMsg("查询失败");
		}
		return r;
	}
	
	/**
	 * 修改ec
	 * @return
	 */
	@Transactional
	public R updateParam(Param params){
		R r=new  R();
		
		try {
			 if(params==null || R.isNull(params.getId()) || R.isNull(params.getParamValue())){
				 r.setCode(ResultEncoding.R_PARAMETER);
				 r.setMsg("修改错误,参数错误");
				 return r;
			 }
		     paramMapper.updateParam(params);
		     r.setMsg("修改成功");
		     return r;
		} catch (Exception e) {
			e.printStackTrace();
			 r.setCode(ResultEncoding.R_ERR);
			 r.setMsg("系统错误");
		}
		
		return r;
	}
}
